export default async (ctx, next) => {
  const token = ctx.header.token
  if (!token) {
    await next()
    return
  }
  try {
    const user = await  ctx.db.redisClient.getSync(token.split('_')[0] || 'default')
    ctx.state.user = JSON.parse(user)
    if (ctx.state.user.password !== token) {
      ctx.state.user = null
    }
  } catch (e) {
    ctx.state.user = null
  }
  await next()
}